<template>
	<view class="content">
		<view class="content-child">
			<view class="item">
				<u-icon
					name="order"
					color="#1573FF"
					label="车辆信息"
					label-color="#333333"
					:customStyle="{
						'line-height': '80rpx',
						display: 'block',
						'padding-left': '20rpx',
					}"></u-icon>

				<u-line
					color="#efefef"
					:customStyle="{ 'margin-bottom': '30rpx', display: 'block' }"></u-line>

				<view class="text-line">
					<text class="text-name">车牌号:</text>
					<text class="text-value">{{ intentData.carNo | filterNull }}</text>
				</view>

				<view class="text-line">
					<text class="text-name">车架号:</text>
					<text class="text-value">{{ intentData.vinNo | filterNull }}</text>
				</view>

				<view class="text-line">
					<text class="text-name">品牌/车系/车型:</text>
					<text class="text-value">{{ intentData.brandSeriesModel | filterNull }}</text>
				</view>

				<view class="text-line">
					<text class="text-name">车辆归属:</text>
					<text class="text-value">{{ intentData.deptName | filterNull }}</text>
				</view>

				<view class="text-line">
					<text class="text-name">车辆仓库:</text>
					<text class="text-value">{{ intentData.depotName | filterNull }}</text>
				</view>

				<u-line
					color="#efefef"
					border-style="dashed"
					:customStyle="{ 'margin-bottom': '20rpx', display: 'block' }"></u-line>

				<view class="text-line">
					<text class="text-name">车辆状态:</text>
					<text class="text-value">{{ intentData.carStatusShow | filterNull }}</text>
				</view>
			</view>

			<view class="item" style="padding: 20rpx" v-if="addType == 1">
				<u-form :model="insuranceCompulsoryDto" ref="uform" label-width="auto">
					<u-form-item label="保险公司" @click="pickerShow(1)" borderBottom required>
						<u--input
							v-model="insuranceCompulsoryDto.compulsoryCompany"
							disabled
							disabledColor="#ffffff"
							border="none"
							inputAlign="right"
							placeholder="请选择保险公司"
							type="select"
							:select-open="actionSheetShow"></u--input>
						<u-icon slot="right" name="arrow-right"></u-icon>
					</u-form-item>

					<u-form-item
						label="交强险开始时间"
						@click="pickerShow(2)"
						borderBottom
						required>
						<u-input
							v-model="insuranceCompulsoryDto.compulsoryStartTime"
							disabled
							disabledColor="#ffffff"
							border="none"
							inputAlign="right"
							placeholder="请选择开始日期"
							type="select"
							:select-open="actionSheetShow"></u-input>
						<u-icon slot="right" name="arrow-right"></u-icon>
					</u-form-item>

					<u-form-item
						label="交强险结束时间"
						@click="pickerShow(3)"
						borderBottom
						required>
						<u-input
							v-model="insuranceCompulsoryDto.compulsoryEndTime"
							disabled
							disabledColor="#ffffff"
							border="none"
							inputAlign="right"
							placeholder="请选择结束日期"
							type="select"
							:select-open="actionSheetShow"></u-input>
						<u-icon slot="right" name="arrow-right"></u-icon>
					</u-form-item>

					<u-form-item label="交强险保单号" borderBottom>
						<u-input
							v-model="insuranceCompulsoryDto.compulsoryNo"
							inputAlign="right"
							border="none"
							placeholder="输入保险单号"></u-input>
					</u-form-item>

					<u-form-item label="费用" borderBottom>
						<u-input
							v-model="insuranceCompulsoryDto.compulsoryAmount"
							@change="compulsoryAmountChange"
							ref="fee0"
							inputAlign="right"
							border="none"
							placeholder="请输入费用"></u-input>
					</u-form-item>
					<u-form-item label="分期数" borderBottom>
						<u-input v-model="insuranceCompulsoryDto.compulsoryFeePeriods" :disabled="compulsoryYearlyStatus" @change="compulsoryNumberChange" type="number" border="none" inputAlign="right" placeholder="请输入"></u-input>
					</u-form-item>

					<u-form-item label="备注" borderBottom>
						<u-input
							v-model="insuranceCompulsoryDto.compulsoryRemark"
							inputAlign="right"
							border="none"
							placeholder="请输入备注"></u-input>
					</u-form-item>

					<text style="padding: 20rpx 0; display: block; font-size: 30rpx; color: #333">
						保单照片
					</text>

					<lr-upload @on-change="onListChange" :tag="1" :objType="15"></lr-upload>
					<u-collapse>
						<u-collapse-item :title="item.title" v-for="(item, index) in insuranceCompulsoryDto.compulsoryInstallmentPlan" :key="index">
						<u-form-item label="账单类型" borderBottom>
							<u-input v-model="item.feeName" border="none" inputAlign="right"  disabled></u-input>
						</u-form-item>
						<u-form-item label="应付金额/元" borderBottom>
							<u-input v-model="item.payableAmount" border="none" inputAlign="right" placeholder="请输入" ></u-input>
						</u-form-item>
						<u-form-item label="应付日期" borderBottom @click="pickerShow(10,item)">
							<u-input
							v-model="item.payableTime"
							disabled disabledColor="#ffffff" border="none"
							inputAlign="right" 
							placeholder="请选择" 
							></u-input>
							<u-icon slot="right" name="arrow-right"></u-icon>
						</u-form-item>
						<u-form-item label="备注" borderBottom>
							<u-input v-model="item.remark" border="none" inputAlign="right" placeholder="请输入" type="textarea"></u-input>
						</u-form-item>
						<u-form-item label="生成应付账单" borderBottom>
							<u-switch v-model="item.isGenerateBill" slot="right"></u-switch>	
						</u-form-item>
						
						</u-collapse-item>
					</u-collapse>
				</u-form>
			</view>

			<view class="item" style="padding: 20rpx" v-if="addType == 3">
				<u-form :model="insuranceCarrierDto" ref="uform" label-width="auto">
					<u-form-item label="保险公司" @click="pickerShow(7)" borderBottom required>
						<u--input
							v-model="insuranceCarrierDto.carrierCompany"
							disabled
							disabledColor="#ffffff"
							border="none"
							inputAlign="right"
							placeholder="请选择保险公司"
							type="select"
							:select-open="actionSheetShow"></u--input>
						<u-icon slot="right" name="arrow-right"></u-icon>
					</u-form-item>

					<u-form-item
						label="承运险开始时间"
						@click="pickerShow(8)"
						borderBottom
						required>
						<u-input
							v-model="insuranceCarrierDto.carrierStartTime"
							disabled
							disabledColor="#ffffff"
							border="none"
							inputAlign="right"
							placeholder="请选择开始日期"
							type="select"
							:select-open="actionSheetShow"></u-input>
						<u-icon slot="right" name="arrow-right"></u-icon>
					</u-form-item>

					<u-form-item
						label="承运险结束时间"
						@click="pickerShow(9)"
						borderBottom
						required>
						<u-input
							v-model="insuranceCarrierDto.carrierEndTime"
							disabled
							disabledColor="#ffffff"
							border="none"
							inputAlign="right"
							placeholder="请选择结束日期"
							type="select"
							:select-open="actionSheetShow"></u-input>
						<u-icon slot="right" name="arrow-right"></u-icon>
					</u-form-item>

					<u-form-item label="承运险保单号" borderBottom>
						<u-input
							v-model="insuranceCarrierDto.carrierNo"
							inputAlign="right"
							border="none"
							placeholder="输入保险单号"></u-input>
					</u-form-item>

					<u-form-item label="费用" borderBottom>
						<u-input
							v-model="insuranceCarrierDto.carrierAmount"
							@change="insuranceAmountChange"
							ref="fee1"
							inputAlign="right"
							border="none"
							placeholder="请输入费用"></u-input>
					</u-form-item>
					<u-form-item label="分期数" borderBottom>
						<u-input v-model="insuranceCarrierDto.carrierFeePeriods" :disabled="insuranceYearlyStatus" @change="insuranceNumberChange" type="number" border="none" inputAlign="right" placeholder="请输入"></u-input>
					</u-form-item>

					<u-form-item label="备注" borderBottom>
						<u-input
							v-model="insuranceCarrierDto.carrierRemark"
							inputAlign="right"
							border="none"
							placeholder="请输入备注"></u-input>
					</u-form-item>

					<text style="padding: 20rpx 0; display: block; font-size: 30rpx; color: #333">
						保单照片
					</text>

					<lr-upload @on-change="onListChange" :tag="3" :objType="49"></lr-upload>
					<u-collapse>
						<u-collapse-item :title="item.title" v-for="(item, index) in insuranceCarrierDto.carrierInstallmentPlan" :key="index">
						<u-form-item label="账单类型" borderBottom>
							<u-input v-model="item.feeName" border="none" inputAlign="right"  disabled></u-input>
						</u-form-item>
						<u-form-item label="应付金额/元" borderBottom>
							<u-input v-model="item.payableAmount" border="none" inputAlign="right" placeholder="请输入" ></u-input>
						</u-form-item>
						<u-form-item label="应付日期" borderBottom @click="pickerShow(15,item)">
							<u-input
							v-model="item.payableTime"
							disabled disabledColor="#ffffff" border="none"
							inputAlign="right" 
							placeholder="请选择" 
							></u-input>
							<u-icon slot="right" name="arrow-right"></u-icon>
						</u-form-item>
						<u-form-item label="备注" borderBottom>
							<u-input v-model="item.remark" border="none" inputAlign="right" placeholder="请输入" type="textarea"></u-input>
						</u-form-item>
						<u-form-item label="生成应付账单" borderBottom>
							<u-switch v-model="item.isGenerateBill" slot="right"></u-switch>	
						</u-form-item>
						
						</u-collapse-item>
					</u-collapse>
				</u-form>
			</view>

			<view class="item" style="padding: 20rpx" v-if="addType == 2">
				<u-form :model="commercialAddPO" ref="uform" label-width="auto">
					<u-form-item label="保险公司" @click="pickerShow(4)" borderBottom required>
						<u-input
							v-model="commercialAddPO.commercialCompany"
							inputAlign="right"
							disabled
							disabledColor="#ffffff"
							border="none"
							placeholder="请选择保险公司"
							type="select"
							:select-open="actionSheetShow"></u-input>
						<u-icon slot="right" name="arrow-right"></u-icon>
					</u-form-item>

					<u-form-item
						label="商业险开始时间"
						@click="pickerShow(5)"
						borderBottom
						required>
						<u-input
							v-model="commercialAddPO.commercialStartTime"
							inputAlign="right"
							disabled
							disabledColor="#ffffff"
							border="none"
							placeholder="请选择开始日期"
							type="select"
							:select-open="actionSheetShow"></u-input>
						<u-icon slot="right" name="arrow-right"></u-icon>
					</u-form-item>

					<u-form-item
						label="商业险结束时间"
						@click="pickerShow(6)"
						borderBottom
						required>
						<u-input
							v-model="commercialAddPO.commercialEndTime"
							inputAlign="right"
							disabled
							disabledColor="#ffffff"
							border="none"
							placeholder="请选择结束日期"
							type="select"
							:select-open="actionSheetShow"></u-input>
						<u-icon slot="right" name="arrow-right"></u-icon>
					</u-form-item>

					<u-form-item label="商业险保单号" borderBottom>
						<u-input
							v-model="commercialAddPO.commercialNo"
							inputAlign="right"
							placeholder="输入保险单号"
							border="none"></u-input>
					</u-form-item>
					<u-form-item label="商业险险种" @click="addCommercialTypes" borderBottom>
						<u-input
							v-model="commercialTypeTitle"
							inputAlign="right"
							disabled
							disabledColor="#ffffff"
							border="none"
							placeholder="添加商业险险种"
							type="select"
							:select-open="actionSheetShow"></u-input>
						<u-icon slot="right" name="arrow-right"></u-icon>
					</u-form-item>
					<u-form-item label="费用" borderBottom>
						<u-input
							v-model="commercialAddPO.commercialAmount"
							inputAlign="right"
							disabled="true"
							disabledColor="#ffffff"
							border="none"
							placeholder="费用"></u-input>
					</u-form-item>
					
					<u-form-item label="分期数" borderBottom>
						<u-input v-model="commercialAddPO.commercialFeePeriods" :disabled="commercialYearlyStatus" @change="commercialNumberChange" type="number" border="none" inputAlign="right" placeholder="请输入"></u-input>
					</u-form-item>
					
					<u-form-item label="备注" borderBottom>
						<u-input
							v-model="commercialAddPO.commercialRemark"
							inputAlign="right"
							border="none"
							placeholder="请输入备注"></u-input>
					</u-form-item>

					<text style="padding: 20rpx 0; display: block; font-size: 30rpx; color: #333">
						保单照片
					</text>

					<lr-upload @on-change="onListChange" :tag="2" :objType="12"></lr-upload>
					<u-collapse>
						<u-collapse-item :title="item.title" v-for="(item, index) in commercialAddPO.commercialInstallmentPlan" :key="index">
						<u-form-item label="账单类型" borderBottom>
							<u-input v-model="item.feeName" border="none" inputAlign="right"  disabled></u-input>
						</u-form-item>
						<u-form-item label="应付金额/元" borderBottom>
							<u-input v-model="item.payableAmount" border="none" inputAlign="right" placeholder="请输入" ></u-input>
						</u-form-item>
						<u-form-item label="应付日期" borderBottom @click="pickerShow(11,item)">
							<u-input
							v-model="item.payableTime"
							disabled disabledColor="#ffffff" border="none"
							inputAlign="right" 
							placeholder="请选择" 
							></u-input>
							<u-icon slot="right" name="arrow-right"></u-icon>
						</u-form-item>
						<u-form-item label="备注" borderBottom>
							<u-input v-model="item.remark" border="none" inputAlign="right" placeholder="请输入" type="textarea"></u-input>
						</u-form-item>
						<u-form-item label="生成应付账单" borderBottom>
							<u-switch v-model="item.isGenerateBill" slot="right"></u-switch>	
						</u-form-item>
						
						</u-collapse-item>
					</u-collapse>
				</u-form>
			</view>

			<!-- 交强险保险公司 -->
			<u-picker
				:show="compulsoryCompanyShow"
				:columns="carInsuranceCompanyList"
				keyName="companyName"
				@confirm="pickerConfim"
				@cancel="compulsoryCompanyShow = false"></u-picker>

			<!-- 商业险保险公司 -->
			<u-picker
				:show="commercialCompanyShow"
				:columns="carInsuranceCompanyList"
				keyName="companyName"
				@confirm="pickerConfim()"
				@cancel="commercialCompanyShow = false"></u-picker>

			<!-- 承运险保险公司 -->
			<u-picker
				:show="carrierCompanyShow"
				:columns="carInsuranceCompanyList"
				keyName="companyName"
				@confirm="pickerConfim()"
				@cancel="carrierCompanyShow = false"></u-picker>
			<!-- 承运险应付日期 -->
			<u-datetime-picker
				:show="insuranceDuedateShow"
				v-model="value1"
				:maxDate="value2"
				mode="date"
				@confirm="timeconfirm"
				@cancel="insuranceDuedateShow = false"></u-datetime-picker>
			<!-- 商业险应付日期 -->
			<u-datetime-picker
				:show="commercialDuedateShow"
				v-model="value1"
				:maxDate="value2"
				mode="date"
				@confirm="timeconfirm"
				@cancel="commercialDuedateShow = false"></u-datetime-picker>
			<!-- 交强险应付日期 -->
			<u-datetime-picker
				:show="compulsoryDuedateShow"
				v-model="value1"
				:maxDate="value2"
				mode="date"
				@confirm="timeconfirm"
				@cancel="compulsoryDuedateShow = false"></u-datetime-picker>
			<!-- 强险开始时间 -->
			<u-datetime-picker
				:show="compulsoryStartShow"
				v-model="value1"
				:maxDate="value2"
				mode="date"
				@confirm="timeconfirm"
				@cancel="compulsoryStartShow = false"></u-datetime-picker>
			<!-- <u-picker :mode="mode" :show="compulsoryStartShow" @confirm="pickerConfim()"></u-picker> -->
			<!-- 强险结束时间 -->
			<u-datetime-picker
				:show="compulsoryEndShow"
				mode="date"
				v-model="value2"
				:minDate="value1"
				@confirm="timeconfirm"
				@cancel="compulsoryEndShow = false"></u-datetime-picker>
			<!-- <u-picker :mode="mode" :show="compulsoryEndShow" @confirm="pickerConfim()"></u-picker> -->

			<!-- 承运险开始时间 -->
			<u-datetime-picker
				:show="carrierStartShow"
				v-model="value5"
				:maxDate="value6"
				mode="date"
				@confirm="timeconfirm"
				@cancel="carrierStartShow = false"></u-datetime-picker>
			<!-- <u-picker :mode="mode" :show="compulsoryStartShow" @confirm="pickerConfim()"></u-picker> -->
			<!-- 承运结束时间 -->
			<u-datetime-picker
				:show="carrierEndShow"
				mode="date"
				v-model="value6"
				:minDate="value5"
				@confirm="timeconfirm"
				@cancel="carrierEndShow = false"></u-datetime-picker>
			<!-- <u-picker :mode="mode" :show="compulsoryEndShow" @confirm="pickerConfim()"></u-picker> -->

			<!-- 商险开始时间 -->
			<u-datetime-picker
				:show="commercialStartShow"
				mode="date"
				v-model="value3"
				:maxDate="value4"
				@confirm="timeconfirm"
				@cancel="commercialStartShow = false"></u-datetime-picker>
			<!-- <u-picker :mode="mode" :show="commercialStartShow" @confirm="pickerConfim()"></u-picker> -->
			<!-- 商险结束时间 -->
			<u-datetime-picker
				:show="commercialEndShow"
				mode="date"
				v-model="value4"
				:minDate="value3"
				@confirm="timeconfirm"
				@cancel="commercialEndShow = false"></u-datetime-picker>
			<!-- <u-picker :mode="mode" :show="commercialEndShow" @confirm="pickerConfim()"></u-picker> -->

			<u-modal
				ref="uModal"
				:show="showModal"
				:show-cancel-button="true"
				show-title=""
				@confirm="confirm"
				@cancel="showModal = false"
				content="确定提交？">
				<!-- #ifndef MP-WEIXIN || MP-TOUTIAO -->
				<!-- <view class="warp" style="margin: 30rpx;" v-if="contentSlot">
          <image class="logo" src="https://uviewui.com/common/logo.png" style="width: 220rpx;"
            mode="widthFix"></image>
        </view> -->
				<!-- #endif -->
			</u-modal>
		</view>

		<examflow
			:from="pageType"
			:instanceId="instanceId"
			approvalName="carInsuranceApprove"
			:isAdd="'add' == pageType"></examflow>

		<view style="height: 100rpx"></view>

		<!-- <view class="bottom">
      <text @click="commit">提 交</text>

    </view> -->

		<view class="button-container">
			<button class="btn-item" @click="commit">提 交</button>
		</view>
	</view>
</template>

<script>
	import lrUpload from '../../components/global/lr-upload.vue';
	import examflow from '@/components/exam-flow.vue';

	export default {
		components: {
			lrUpload,
			examflow,
		},
		data() {
			return {
				value1: Number(new Date()),
				value2: Number(new Date()) + 12 * 30 * 24 * 3600 * 1000,
				value3: Number(new Date()),
				value4: Number(new Date()) + 12 * 30 * 24 * 3600 * 1000,
				value5: Number(new Date()),
				value6: Number(new Date()) + 12 * 30 * 24 * 3600 * 1000,
				pageType: '',
				instanceId: '',
				addType: 0,
				// mode: '',
				commercialTypeTitle: '',
				type: 0,
				showModal: false,
				compulsoryCompanyShow: false,
				compulsoryStartShow: false,
				compulsoryEndShow: false,

				commercialCompanyShow: false,
				commercialStartShow: false,
				commercialEndShow: false,

				carrierCompanyShow: false,
				carrierStartShow: false,
				carrierEndShow: false,
				
				compulsoryYearlyStatus:true,
				insuranceYearlyStatus:true,
				compulsoryYearlyItem:null,
				compulsoryDuedateShow:false,
				commercialDuedateShow:false,
				insuranceDuedateShow:false,
				commercialYearlyStatus:true,
				commercialYearlyItem:null,
				insuranceYearlyItem:null,

				intentData: {},
				carInsuranceCompanyList: [],
				//交强险信息
				insuranceCompulsoryDto: {
					// compulsoryStartTime: String,
					// compulsoryEndTime: String,
					// compulsoryNo: String,
					// compulsoryCompanyId: String,
					// compulsoryCompany: String,
					// compulsoryAmount: String,
					// compulsoryRemark: String,
					compulsorySysAccessoryList: [],
					inspectNumber:null,
					compulsoryInstallmentPlan:[],
				},
				//商业险信息
				commercialAddPO: {
					// commercialStartTime: String,
					// commercialEndTime: String,
					// commercialNo: String,
					// commercialCompanyId: String,
					// commercialCompany: String,
					// commercialAmount: String,
					// commercialRemark: String,
					commercialAmount:null,
					commercialInsuranceRecordList: [],
					commercialInstallmentPlan:[],
					// commercialSysAccessoryList: []
				},
				//承运险
				insuranceCarrierDto: {
					carrierSysAccessoryList: [],
					carrierInstallmentPlan:[],
					carrierAmount:null,
				},
			};
		},
		watch:{
			intentData:{
				deep:true,
				handler(val){
					this.intentData = val
				}
			},
			commercialAddPO:{
				deep:true,
				handler(val){
					this.commercialAddPO =val
					// 商业险的金额是带出来,所以在这里控制分期数的的状态
					if(val.commercialAmount){
						this.commercialYearlyStatus = false
						console.log(val.commercialAmount,111)
					}else{
						this.commercialYearlyStatus = true
					}
				},
			},
			insuranceCarrierDto:{
				deep:true,
				handler(val){
					this.insuranceCarrierDto = val
				}
			},
			insuranceCompulsoryDto:{
				deep:true,
				handler(val){
					this.insuranceCompulsoryDto = val
				}
			},
			'insuranceCarrierDto.carrierInstallmentPlan':{
				deep:true,
				handler(val){
					this.insuranceCarrierDto.carrierInstallmentPlan = val
				}
			},
			'commercialAddPO.commercialInstallmentPlan':{
				deep:true,
				handler(val){
					this.commercialAddPO.commercialInstallmentPlan = val
				}
			},
			'insuranceCompulsoryDto.compulsoryInstallmentPlan':{
				deep:true,
				handler(val){
					this.insuranceCompulsoryDto.compulsoryInstallmentPlan = val
				}
			},
		},
		onLoad(options) {
			uni.setNavigationBarTitle({
				title:
					options.type == 1
						? '新增交强保险'
						: options.type == 2
						? '新增商业保险'
						: '新增承运保险',
			});

			this.addType = options.type;
			this.pageType = options.pageType;
			this.instanceId = options.instanceId;
			let dataInfo = JSON.parse(options.intentData);
			this.intentData = dataInfo.vehicle
			this.insuranceCompulsoryDto = dataInfo.insuranceCompulsoryDto
			this.commercialAddPO = dataInfo.insuranceCommercialDto
			this.insuranceCarrierDto = dataInfo.insuranceCarrierDto
			console.log('收到传递数据');
			console.log(dataInfo);

			//获取缓存中的保险公司
			this.carInsuranceCompanyList = [this.$store.state.params.insuranceCompanyList];
			console.log('保险公司数据', this.carInsuranceCompanyList);

			uni.$on('addInsType', res => {
				this.commercialAddPO.commercialInsuranceRecordList =
					res.commercialInsuranceRecordList;
				this.commercialAddPO.commercialAmount = res.commercialAmount;
				this.commercialTypeTitle = res.commercialTypeTitle;
			});

			this.$nextTick(() => {
				setTimeout(() => {
					this.$refs.fee0 &&
						this.$refs.fee0.setFormatter(e => {
							return e
								.replace(/[^\d.]/g, '')
								.replace(/\.{2,}/g, '.')
								.replace(/^(-)*(\d+)\.(\d\d).*$/, '$1$2.$3');
						});
					this.$refs.fee1 &&
						this.$refs.fee1.setFormatter(e => {
							return e
								.replace(/[^\d.]/g, '')
								.replace(/\.{2,}/g, '.')
								.replace(/^(-)*(\d+)\.(\d\d).*$/, '$1$2.$3');
						});
				}, 0);
			});
		},
		methods: {
			
			formatMoney(amount) {
			  return amount.toLocaleString();
			},
			divideMoney(amount, divisor) {
			  return this.formatMoney(amount) / this.formatMoney(divisor)
			},
			// 交强险金额
			compulsoryAmountChange(event){
				const reg = /^\d+(\.\d{1,4})?$/
				if(reg.test(event)){
					this.compulsoryYearlyStatus = false
				}else{
					this.compulsoryYearlyStatus = true
					uni.showToast({
						icon: 'none',
						title:"请输入正确金额",
						
					})
				}
			},
			// 承运险金额
			insuranceAmountChange(event){
				const reg = /^\d+(\.\d{1,4})?$/
				if(reg.test(event)){
					this.insuranceYearlyStatus = false
				}else{
					this.insuranceYearlyStatus = true
					uni.showToast({
						icon: 'none',
						title:"请输入正确金额",
						
					})
				}
			},
			// 交强险保险期数改变
			compulsoryNumberChange(event){
				if(this.insuranceCompulsoryDto.compulsoryAmount && this.insuranceCompulsoryDto.compulsoryAmount !==null){
					const reg = /^\+?[1-9]\d*$/
					if(reg.test(event)){
						const cost = Number(this.insuranceCompulsoryDto.compulsoryAmount)
						const periods = Number(event)
						const payNum = this.divideMoney(cost,periods)
						// const payNum = cost/periods
						console.log(payNum,'payNum')
						this.insuranceCompulsoryDto.compulsoryInstallmentPlan = []
						for (let i =0;i<event;i++){
							setTimeout(()=>{
								const num = this.insuranceCompulsoryDto.compulsoryInstallmentPlan?.length
								let obj = {
									payableAmount:payNum,
									remark:null,
									payableTime:null,
									type:1,
									feeName:"交强险费用",
									isGenerateBill:false,
									title:`第${num+1}期`,
									ids:new Date().getTime()
								}
								this.insuranceCompulsoryDto.compulsoryInstallmentPlan.push(obj)
							},200)
							
						}
						
					}else{
						this.insuranceCompulsoryDto.compulsoryInstallmentPlan = []
						uni.showToast({
							icon: 'none',
							title:"请输入小于100的正整数",
							
						})
					}
				}else{
					this.$set(this.insuranceCompulsoryDto,'inspectNumber',null)
					uni.showToast({
						icon: 'none',
						title:"请先输入费用",
						
					})
				}
			},
			// 承运险保险期数改变
			insuranceNumberChange(event){
				if(this.insuranceCarrierDto.carrierAmount && this.insuranceCarrierDto.carrierAmount !==null){
					const reg = /^\+?[1-9]\d*$/
					if(reg.test(event)){
						const cost = Number(this.insuranceCarrierDto.carrierAmount)
						const periods = Number(event)
						const payNum = this.divideMoney(cost,periods)
						// const payNum = cost/periods
						console.log(payNum,'payNum')
						this.insuranceCarrierDto.carrierInstallmentPlan = []
						for (let i =0;i<event;i++){
							setTimeout(()=>{
								const num = this.insuranceCarrierDto.carrierInstallmentPlan?.length
								let obj = {
									payableAmount:payNum,
									remark:null,
									payableTime:null,
									type:3,
									feeName:'承运险费用',
									isGenerateBill:false,
									title:`第${num+1}期`,
									ids:new Date().getTime()
								}
								this.insuranceCarrierDto.carrierInstallmentPlan.push(obj)
							},200)
							
						}
						
					}else{
						this.insuranceCarrierDto.carrierInstallmentPlan = []
						uni.showToast({
							icon: 'none',
							title:"请输入小于100的正整数",
							
						})
					}
				}else{
					this.$set(this.insuranceCarrierDto,'inspectNumber',null)
					uni.showToast({
						icon: 'none',
						title:"请先输入费用",
						
					})
				}
			}
			,
			//商业保险期数改变
			commercialNumberChange(event){
				if(this.commercialAddPO.commercialAmount && this.commercialAddPO.commercialAmount !==null){
					const reg = /^\+?[1-9]\d*$/
					if(reg.test(event)){
						const cost = Number(this.commercialAddPO.commercialAmount)
						const periods = Number(event)
						const payNum = this.divideMoney(cost,periods)
						// const payNum = cost/periods
						console.log(payNum,'payNum')
						this.commercialAddPO.commercialInstallmentPlan = []
						for (let i =0;i<event;i++){
							setTimeout(()=>{
								const num = this.commercialAddPO.commercialInstallmentPlan?.length
								let obj = {
									payableAmount:payNum,
									remark:null,
									payableTime:null,
									type:2,
									feeName:'商业保险费用',
									isGenerateBill:false,
									title:`第${num+1}期`,
									ids:new Date().getTime()
								}
								this.commercialAddPO.commercialInstallmentPlan.push(obj)
							},200)
							
						}
						
					}else{
						this.commercialAddPO.commercialInstallmentPlan = []
						uni.showToast({
							icon: 'none',
							title:"请输入小于100的正整数",
							
						})
					}
				}else{
					this.$set(this.commercialAddPO,'inspectNumber',null)
					uni.showToast({
						icon: 'none',
						title:"请先输入费用",
						
					})
				}
			},
			pickerShow(type,item) {
				console.log('点击了' + type);

				this.type = type;
				switch (type) {
					case 1:
						this.compulsoryCompanyShow = true;
						// this.mode = 'selector';
						break;
					case 2:
						this.compulsoryStartShow = true;
						// this.mode = 'time';
						break;
					case 3:
						this.compulsoryEndShow = true;
						// this.mode = 'time';
						break;
					case 4:
						this.commercialCompanyShow = true;
						// this.mode = 'selector';
						break;
					case 5:
						this.commercialStartShow = true;
						// this.mode = 'time';
						break;
					case 6:
						this.commercialEndShow = true;
						// this.mode = 'time';
						break;
					case 7:
						this.carrierCompanyShow = true;
						// this.mode = 'time';
						break;
					case 8:
						this.carrierStartShow = true;
						// this.mode = 'time';
						break;
					case 9:
						this.carrierEndShow = true;
						// this.mode = 'time';
						break;
					case 10:
						this.compulsoryDuedateShow = true;	
						this.compulsoryYearlyItem = item
						break;
					case 11:
						this.commercialDuedateShow = true;	
						this.commercialYearlyItem = item
					case 15:
						this.insuranceDuedateShow = true;	
						this.insuranceYearlyItem = item
				}
			},
			formatter(type, value) {
				if (type === 'year') {
					return `${value}年`;
				}
				if (type === 'month') {
					return `${value}月`;
				}
				if (type === 'day') {
					return `${value}日`;
				}
				return value;
			},
			pickerConfim(e) {
				console.log('点击确认了', e);

				// if (this.mode == 'time') {
				// let timeStr = e.year + "-" + e.month + "-" + e.day;
				// if (this.type == 2) {
				// 	this.insuranceCompulsoryDto.compulsoryStartTime = timeStr;
				// } else if (this.type == 3) {
				// 	this.insuranceCompulsoryDto.compulsoryEndTime = timeStr;
				// } else if (this.type == 5) {
				// 	this.commercialAddPO.commercialStartTime = timeStr;
				// } else if (this.type == 6) {
				// 	this.commercialAddPO.commercialEndTime = timeStr;
				// }
				// } else if (this.mode == 'selector') {
				if (this.type == 1) {
					this.compulsoryCompanyShow = false;
					// let index = e;
					this.insuranceCompulsoryDto.compulsoryCompany = e.value[0].companyName;
					this.insuranceCompulsoryDto.compulsoryCompanyId = e.value[0].companyId;

					console.log('选定的', e.value[0].companyName);
				} else if (this.type == 4) {
					this.commercialCompanyShow = false;
					// let index = e;
					this.commercialAddPO.commercialCompany = e.value[0].companyName;
					this.commercialAddPO.commercialCompanyId = e.value[0].companyId;
				} else if (this.type == 7) {
					this.carrierCompanyShow = false;
					// let index = e;
					this.insuranceCarrierDto.carrierCompany = e.value[0].companyName;
					this.insuranceCarrierDto.carrierCompanyId = e.value[0].companyId;
				}
				// }
			},

			timeconfirm(e) {
				console.log('点击确认了', e);
				let timeStr = uni.$u.timeFormat(e.value, 'yyyy-mm-dd');
				console.log('格式化后', timeStr);

				// let timeStr = e.year + "-" + e.month + "-" + e.day;
				if (this.type == 2) {
					this.compulsoryStartShow = false;
					this.insuranceCompulsoryDto.compulsoryStartTime = timeStr;
				} else if (this.type == 3) {
					this.compulsoryEndShow = false;
					this.insuranceCompulsoryDto.compulsoryEndTime = timeStr;
				} else if (this.type == 5) {
					this.commercialStartShow = false;
					this.commercialAddPO.commercialStartTime = timeStr;
				} else if (this.type == 6) {
					this.commercialEndShow = false;
					this.commercialAddPO.commercialEndTime = timeStr;
				} else if (this.type == 8) {
					this.carrierStartShow = false;
					this.insuranceCarrierDto.carrierStartTime = timeStr;
				} else if (this.type == 9) {
					this.carrierEndShow = false;
					this.insuranceCarrierDto.carrierEndTime = timeStr;
				}else if (this.type == 10) {
					this.compulsoryDuedateShow = false;
					this.insuranceCompulsoryDto.compulsoryInstallmentPlan?.map((res)=>{
						console.log(res)
						if(res.ids==this.compulsoryYearlyItem.ids){
							this.$set(res,'payableTime',timeStr)
							res.payableTime = timeStr
						}
					})
				}else if (this.type == 11) {
					this.commercialDuedateShow = false;
					this.commercialAddPO.commercialInstallmentPlan?.map((res)=>{
						console.log(res)
						if(res.ids==this.commercialYearlyItem.ids){
							this.$set(res,'payableTime',timeStr)
							res.payableTime = timeStr
						}
					})
				}else if (this.type == 15) {
					this.insuranceDuedateShow = false;
					this.insuranceCarrierDto.carrierInstallmentPlan?.map((res)=>{
						console.log(res)
						if(res.ids==this.insuranceYearlyItem.ids){
							this.$set(res,'payableTime',timeStr)
							res.payableTime = timeStr
						}
					})
				}

				console.log('选中的时间', this.insuranceCompulsoryDto.compulsoryStartTime);
			},

			//添加商业险险种
			addCommercialTypes() {
				var intentData = JSON.stringify(this.commercialAddPO.commercialInsuranceRecordList);
				uni.navigateTo({
					url: '../addCar/addCar-insuranceTypeList?insuranceRecordList=' + intentData,
				});
			},
			commit() {
				// this.showModal = true;
				let that = this;

				//   title: options.type == 1 ? "新增交强保险" : "新增商业保险"
				// });
				//
				// this.addType = options.type;

				if (that.addType == 1) {
					if (uni.$u.test.isEmpty(that.insuranceCompulsoryDto.compulsoryCompany)) {
						uni.showToast({ title: '请选择保险公司', icon: 'error' });
						return;
					}

					if (uni.$u.test.isEmpty(that.insuranceCompulsoryDto.compulsoryStartTime)) {
						uni.showToast({ title: '请选择开始时间', icon: 'error' });
						return;
					}

					if (uni.$u.test.isEmpty(that.insuranceCompulsoryDto.compulsoryEndTime)) {
						uni.showToast({ title: '请选择结束时间', icon: 'error' });
						return;
					}
					let data = JSON.parse(JSON.stringify(that.insuranceCompulsoryDto))
					// 交强保险费用
					const cost1 = Number(data.compulsoryAmount)
					let num1 =0
					data?.compulsoryInstallmentPlan?.map((res)=>{
						if(res.isGenerateBill==true){
							that.$set(res,'isGenerateBill',1)
						}else{
							that.$set(res,'isGenerateBill',0)
						}
						num1 = num1 + Number(res.payableAmount)
					})
					if(num1 !==cost1){
						uni.showToast({
							icon: 'none',
							title:"分期数金额不等于总费用",
							
						})
						return
					}
					
					uni.showModal({
						content: '确定提交吗?',
						success(res) {
							if (res.confirm) {
								that.$u.api
									.saveCompulsory({
										vehicle: that.intentData,
										insuranceCompulsoryDto: data,
										// insuranceCommercialDto: that.commercialAddPO,
										// orderCar:
									})
									.then(res => {
										uni.showToast({
											title: '提交成功',
											icon: 'none',
										});
										setTimeout(() => {
											uni.navigateBack();
										}, 500);
									});
							}
						},
					});
				} else if (that.addType == 2) {
					if (uni.$u.test.isEmpty(that.commercialAddPO.commercialCompany)) {
						uni.showToast({ title: '请选择保险公司', icon: 'error' });
						return;
					}

					if (uni.$u.test.isEmpty(that.commercialAddPO.commercialStartTime)) {
						uni.showToast({ title: '请选择开始时间', icon: 'error' });
						return;
					}

					if (uni.$u.test.isEmpty(that.commercialAddPO.commercialEndTime)) {
						uni.showToast({ title: '请选择结束时间', icon: 'error' });
						return;
					}
					let data = JSON.parse(JSON.stringify(that.commercialAddPO))
					// 商业险费用
					const cost2 = Number(data.commercialAmount)
					let num2 = 0
					data?.commercialInstallmentPlan?.map((res)=>{
						if(res.isGenerateBill==true){
							that.$set(res,'isGenerateBill',1)
						}else{
							that.$set(res,'isGenerateBill',0)
						}
						num2 = num2 + Number(res.payableAmount)
					})
					if(num2 !==cost2){
						uni.showToast({
							icon: 'none',
							title:"分期数金额不等于总费用",
							
						})
						return
					}
					uni.showModal({
						content: '确定提交吗?',
						success(res) {
							if (res.confirm) {
								that.$u.api
									.saveCommercial({
										vehicle: that.intentData,
										// insuranceCompulsoryDto: that.insuranceCompulsoryDto,
										insuranceCommercialDto: data,
										// orderCar:
									})
									.then(res => {
										uni.showToast({
											title: '提交成功',
											icon: 'none',
										});
										setTimeout(() => {
											uni.navigateBack();
										}, 500);
									});
							}
						},
					});
				} else if (that.addType == 3) {
					if (uni.$u.test.isEmpty(that.insuranceCarrierDto.carrierCompany)) {
						uni.showToast({ title: '请选择保险公司', icon: 'error' });
						return;
					}

					if (uni.$u.test.isEmpty(that.insuranceCarrierDto.carrierStartTime)) {
						uni.showToast({ title: '请选择开始时间', icon: 'error' });
						return;
					}

					if (uni.$u.test.isEmpty(that.insuranceCarrierDto.carrierEndTime)) {
						uni.showToast({ title: '请选择结束时间', icon: 'error' });
						return;
					}
					let data = JSON.parse(JSON.stringify(that.insuranceCarrierDto))
					// 承运险费用
					const cost = Number(data.carrierAmount)
					let num = 0
					data?.carrierInstallmentPlan?.map((res)=>{
						if(res.isGenerateBill==true){
							that.$set(res,'isGenerateBill',1)
						}else{
							that.$set(res,'isGenerateBill',0)
						}
						num = num + Number(res.payableAmount)
					})
					if(num !==cost){
						uni.showToast({
							icon: 'none',
							title:"分期数金额不等于总费用",
							
						})
						return
					}
					uni.showModal({
						content: '确定提交吗?',
						success(res) {
							if (res.confirm) {
								that.$u.api
									.saveCarrier({
										vehicle: that.intentData,
										// insuranceCompulsoryDto: that.insuranceCompulsoryDto,
										insuranceCarrierDto: data,
										// orderCar:
									})
									.then(res => {
										uni.showToast({
											title: '提交成功',
											icon: 'none',
										});
										setTimeout(() => {
											uni.navigateBack();
										}, 500);
									});
							}
						},
					});
				}
			},

			confirm() {
				// this.showModal = false;
				// this.$u.api.saveCompulsory({
				//   vehicle: this.intentData,
				//   insuranceCompulsoryDto: this.insuranceCompulsoryDto,
				//   insuranceCommercialDto: this.commercialAddPO,
				//   // orderCar:
				// }).then(
				//     res => {
				//       uni.showToast({
				//         title: '提交成功',
				//         icon: 'none'
				//       });
				//       setTimeout(() => {
				//         uni.navigateBack()
				//       }, 1000)
				//     }
				// );
			},

			onListChange(tag, list, objList) {
				console.log('结果list', list);
				console.log('结果objList', objList);

				if (tag == 1) {
					this.insuranceCompulsoryDto.compulsorySysAccessoryList = objList;
				} else if (tag == 2) {
					this.commercialAddPO.commercialSysAccessoryList = objList;
				} else if (tag == 3) {
					this.insuranceCarrierDto.carrierSysAccessoryList = objList;
				}
			},
		},
	};
</script>

<style lang="scss">
	page {
		height: 100%;
	}

	// u-form-item{
	// 	padding: 0 20rpx;
	// }
</style>
